package logic

import (
	"context"
	"errors"
	user_rpc "week_three/user_srv/proto"
	"week_three/user_srv/service"
)

func (u *UserRpc) UserLogin(ctx context.Context, in *user_rpc.UserLoginReq) (*user_rpc.UserLoginRes, error) {
	user, err := service.GetUserByUsername(in.Username)
	if err != nil {
		return &user_rpc.UserLoginRes{}, err
	}
	if user.Password != in.Password {
		return &user_rpc.UserLoginRes{}, errors.New("wrong password")
	}
	return &user_rpc.UserLoginRes{Userid: uint32(user.ID)}, nil
}

//func (u *UserRpc) SearchCar(ctx context.Context, in *user_rpc.SearchCarReq) (*user_rpc.SearchCarRes, error) {
//	global.CarClient.EsSearch(ctx, &car_rpc.EsSearchReq{
//		Index: in.i,
//		Name:  "",
//	})
//	return
//}
